package com.ruoyi.web.controller.sms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SmsSpeciesReport;
import com.ruoyi.system.service.ISmsSpeciesReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物种上报Controller
 *
 * @author DRIES
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/sms/report")
public class SmsSpeciesReportController extends BaseController
{
    @Autowired
    private ISmsSpeciesReportService smsSpeciesReportService;

    /**
     * 查询物种上报列表
     */
    @PreAuthorize("@ss.hasPermi('sms:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsSpeciesReport smsSpeciesReport)
    {
        startPage();
        List<SmsSpeciesReport> list = smsSpeciesReportService.selectSmsSpeciesReportList(smsSpeciesReport);
        return getDataTable(list);
    }

    /**
     * 导出物种上报列表
     */
    @PreAuthorize("@ss.hasPermi('sms:report:export')")
    @Log(title = "物种上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsSpeciesReport smsSpeciesReport)
    {
        List<SmsSpeciesReport> list = smsSpeciesReportService.selectSmsSpeciesReportList(smsSpeciesReport);
        ExcelUtil<SmsSpeciesReport> util = new ExcelUtil<SmsSpeciesReport>(SmsSpeciesReport.class);
        util.exportExcel(response, list, "物种上报数据");
    }

    /**
     * 获取物种上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsSpeciesReportService.selectSmsSpeciesReportById(id));
    }

    /**
     * 新增物种上报
     */
    @PreAuthorize("@ss.hasPermi('sms:report:add')")
    @Log(title = "物种上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsSpeciesReport smsSpeciesReport)
    {
        return toAjax(smsSpeciesReportService.insertSmsSpeciesReport(smsSpeciesReport));
    }

    /**
     * 修改物种上报
     */
    @PreAuthorize("@ss.hasPermi('sms:report:edit')")
    @Log(title = "物种上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsSpeciesReport smsSpeciesReport)
    {
        return toAjax(smsSpeciesReportService.updateSmsSpeciesReport(smsSpeciesReport));
    }

    /**
     * 删除物种上报
     */
    @PreAuthorize("@ss.hasPermi('sms:report:remove')")
    @Log(title = "物种上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsSpeciesReportService.deleteSmsSpeciesReportByIds(ids));
    }
}
